package com.trt.eatmeat.test;

import com.trt.eatmeat.util.JsonUtils;

import java.util.Stack;

public class ListNode {
      int val;
      ListNode next;
      ListNode(int x) { val = x; }

    public int[] reversePrint(ListNode head) {
        Stack stack = new Stack();
        ListNode temp = head;
        while(temp.next!=null){
            stack.push(temp.val);
            temp = temp.next;
        }
        if(temp.next==null){
            stack.push(temp.val);
        }
        int[] arr = new int[stack.size()];
        for(int i=0;i<arr.length;i++){
            arr[i]=(int)stack.pop();
        }
        return arr;
    }

    public static void main(String[] args) {
        ListNode node = new ListNode(1);
        node.next = new ListNode(2);
        node.next.next = new ListNode(3);
        int[] temp=  node.reversePrint(node);
        System.out.println(JsonUtils.objectToJson(temp));
    }
  }